/**
 *  Document   : RoomBooking
 *  Created on : 17 juil. 2008, 10:21:42
 *  Author     : Rivo
 */

package gla.centralhotel.model;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;


@Entity
@Table(name = "room_booking")
@NamedQueries({@NamedQuery(name = "RoomBooking.findById", query = "SELECT r FROM RoomBooking r WHERE r.id = :id"),
@NamedQuery(name = "RoomBooking.findByBookedDate", query = "SELECT r FROM RoomBooking r WHERE r.bookedDate = :bookedDate"),
@NamedQuery(name = "RoomBooking.findByStartDate", query = "SELECT r FROM RoomBooking r WHERE r.startDate = :startDate"),
@NamedQuery(name = "RoomBooking.findByEndDate", query = "SELECT r FROM RoomBooking r WHERE r.endDate = :endDate"),
@NamedQuery(name = "RoomBooking.findByPrice", query = "SELECT r FROM RoomBooking r WHERE r.price = :price")})
public class RoomBooking implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "id", nullable = false)
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Integer id;
    @Column(name = "booked_date", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date bookedDate;
    @Column(name = "start_date", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date startDate;
    @Column(name = "end_date", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date endDate;
    @Column(name = "price", nullable = false)
    private float price;
//    @OneToMany(cascade = CascadeType.ALL, mappedBy = "refBooking")
//    private Collection<RoomBookingHasRoom> roomBookingHasRoomCollection;
    @JoinColumn(name = "ref_agency", referencedColumnName = "id")
    @ManyToOne
    private Agency refAgency;
    
    // à la main (loic)
    @JoinColumn(name = "ref_customer", referencedColumnName = "id")
    @ManyToOne
    private Customer refCustomer;
    @JoinColumn(name = "ref_room", referencedColumnName = "id")
    @ManyToOne
    private Room refRoom;
    
    @Transient
    private String hotelName;
    @Transient
    private String roomNumber;
    @Transient
    private String roomType;
    @Transient
    private String agencyName;
    @Transient
    private String customerName;
    @Transient
    private String customerFirstName;
    

    public RoomBooking() {
    }

    public RoomBooking(Integer id) {
        this.id = id;
    }

    public RoomBooking(Integer id, Date bookedDate, Date startDate, Date endDate, float price) {
        this.id = id;
        this.bookedDate = bookedDate;
        this.startDate = startDate;
        this.endDate = endDate;
        this.price = price;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Date getBookedDate() {
        return bookedDate;
    }

    public void setBookedDate(Date bookedDate) {
        this.bookedDate = bookedDate;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }

//    public Collection<RoomBookingHasRoom> getRoomBookingHasRoomCollection() {
//        return roomBookingHasRoomCollection;
//    }
//
//    public void setRoomBookingHasRoomCollection(Collection<RoomBookingHasRoom> roomBookingHasRoomCollection) {
//        this.roomBookingHasRoomCollection = roomBookingHasRoomCollection;
//    }

    public Agency getRefAgency() {
        return refAgency;
    }

    public void setRefAgency(Agency refAgency) {
        this.refAgency = refAgency;
    }

    public Customer getRefCustomer() {
        return refCustomer;
    }

    public void setRefCustomer(Customer refC) {
        this.refCustomer  = refC;
    }
    
    public Room getRefRoom() {
        return refRoom;
    }

    public void setRefRoom(Room refR) {
        this.refRoom = refR;
    }
    
    /* Properties d'attribut Transient */
    
    public String getAgencyName()
    {
        return agencyName;
    }

    public void setAgencyName(String agencyName)
    {
        this.agencyName = agencyName;
    }

    public String getCustomerFirstName()
    {
        return customerFirstName;
    }

    public void setCustomerFirstName(String customerFirstName)
    {
        this.customerFirstName = customerFirstName;
    }

    public String getCustomerName()
    {
        return customerName;
    }

    public void setCustomerName(String customerName)
    {
        this.customerName = customerName;
    }

    public String getHotelName()
    {
        return hotelName;
    }

    public void setHotelName(String hotelName)
    {
        this.hotelName = hotelName;
    }

    public String getRoomNumber()
    {
        return roomNumber;
    }

    public void setRoomNumber(String roomNumber)
    {
        this.roomNumber = roomNumber;
    }

    public String getRoomType()
    {
        return roomType;
    }

    public void setRoomType(String roomType)
    {
        this.roomType = roomType;
    }

    /* FIN Properties d'attribut Transient */

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof RoomBooking)) {
            return false;
        }
        RoomBooking other = (RoomBooking) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "gla.centralhotel.model.RoomBooking[id=" + id + "]";
    }

}
